package tecpointbenchmark.startup;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import tecpointbenchmark.controller.Controller;
import tecpointbenchmark.view.GUI;

/**
 *  Main class. Creates instances of controller and view and runs 
 * the GUI.
 * 
 * @author Tecpoint
 */
public class Main
{
    public static boolean debug;

    public static void main(String[] args) 
    {
    	String APP_TITLE = "tecpoint-benchmarking";
    	
    	// Check whether I'm running from inside a jar
    	ClassLoader mCL = ClassLoader.getSystemClassLoader();
    	if( mCL instanceof URLClassLoader ){
    	  URL[] urls = ((URLClassLoader)mCL).getURLs();
    	  for ( URL url: urls ) {
    	      // APP_TITLE has to be set to the filename of your app JAR minus extension beforehand
    	      if(url.getFile().endsWith( APP_TITLE+".jar" )){
    	        // If we end up here, we're running inside a JAR, so we have special lib paths
    	        File natives = new File("natives"); // Or some other folder
    	        System.setProperty( "org.lwjgl.librarypath", natives.getAbsolutePath() );
    	        break;
    	      }
    	    }
    	}
    	
        // Debug mode
        debug = false;

        // Creates a controller and sends it reference to the GUI
        Controller cont = new Controller();
        GUI gui = new GUI(cont);

        // Adds GUI as an observer to ModuleHandler
        cont.setObserver(gui);

        /**
         * Test run. Bypassing GUI. Should be removed when the GUI is
         * working!
         * 0 = hddModule
         * 1 = singleThreadIntegarModule
         * 2 = singleThreadFloatModule
         * 3 = multiThreadFloatModule
         * 4 = RAMModule
         */
        //cont.runBenchmark(cont.getModules().get(5).getId());
    }
    
}
